package main

import "fmt"

func main() {
	// 结构体
	//type 结构体名 struct {
	//
	//}

	type useinfo struct {
		name string
		age int
		height float32
		hobby []string
		moreinfo map[string]interface{}
	}

	var bobo useinfo
	bobo.name = "boge"
	bobo.age = 18
	bobo.height = 178.2
	bobo.hobby = []string{"coding", "sport"}
	bobo.moreinfo = map[string]interface{}{
		"job": "baidu",
		"title": "chengxuyuan",
	}
	fmt.Println(bobo)

	// 第二种 剪短申明
	b := useinfo{
		name: "hha",
		age: 24,
		height: 45.2,
		hobby: []string{"2323", "4434"},
		moreinfo: map[string]interface{}{
			"name": "2323",
		},
	}
	fmt.Println(b)

	// 指针
	var xiaomi *useinfo // 这个是地址
	xiaomi = new(useinfo)
	fmt.Println(xiaomi)
	(*xiaomi).name = "xiaoming"
	(*xiaomi).age = 17
	(*xiaomi).height = 1099
	(*xiaomi).hobby = []string{"funck"}
	// xiaoming====*xiaoming
	xiaomi.moreinfo = map[string]interface{}{
		"name": "2323",
	}
	fmt.Println(xiaomi)

	// 取地址
	var xiaohong *useinfo = &useinfo{
		name: "xiaohong",
		age: 24,
		height: 45.2,
		hobby: []string{"2323", "4434"},
		moreinfo: map[string]interface{}{
			"name": "2323",
		},
	}
	fmt.Println(xiaohong)
	// 结构体注意事项
	// 1.0 结构体是值类型
	user1 := useinfo{
		name: "user1",
		age: 24,
		height: 45.2,
		hobby: []string{"2323", "4434"},
		moreinfo: map[string]interface{}{
			"name": "2323",
		},
	}

	user2 := user1
	fmt.Printf("user1 is: %p, user2 is: %p", &user1, &user2)

	// 2.0 结构体之间可以互选转换吗 相同的字段名 个数才可以

	type integer int

	type role struct {
		authraztion integer
		user useinfo
	}

	// 3.0 结构体 可以作为另外一个结构体的类型
	superAdmin := role{
		authraztion: 1,
		user: useinfo{
			name:     "",
			age:      0,
			height:   0,
			hobby:    nil,
			moreinfo: nil,
		},
	}
	fmt.Println(superAdmin)
}
